package com.winspread.app.web

import android.webkit.ValueCallback
import com.blankj.utilcode.util.ToastUtils
import com.winspread.app.R
import com.winspread.app.databinding.ActivityWebBinding
import com.winspread.mvvm.base.vm.BaseNotVmActivity

class WebActivity : BaseNotVmActivity<ActivityWebBinding>(R.layout.activity_web) {


    override fun initView() {

        val webSettings = binding.web.settings
        webSettings.javaScriptEnabled = true
        webSettings.javaScriptCanOpenWindowsAutomatically = true

        binding.web.loadUrl("file:///android_asset/javascript.html")



    }



    override fun initListenter() {

        binding.webBut.setOnClickListener {

            binding.web.post {
                binding.web.evaluateJavascript("javascript:callJS()", ValueCallback {
                    ToastUtils.showShort(it)
                })

            }
        }




//    binding.web.webChromeClient = object : WebChromeClient() {
//        override fun onJsAlert(view: WebView?, url: String?, message: String?, result: JsResult?): Boolean {
//            val alertDialog = AlertDialog.Builder(this@WebActivity)
//            alertDialog.setTitle("alert")
//            alertDialog.setMessage(message)
//            alertDialog.setPositiveButton(android.R.string.ok,DialogInterface.OnClickListener { dialog, which ->
//                result?.confirm()
//            })
//            alertDialog.setCancelable(false)
//            alertDialog.create().show()
//            return true
//        }
//    }
//
    }

}